package ch9.inner;

import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.*;

import ch3.Sex;
import ch3.Student;

public class Xml2Obj {

	public static void main(String[] args) throws IOException {
		List<Student> li = new ArrayList<>();
		// Student必须有无参的构造方法,属性必须有set/get
		for (int i = 1; i <= 20; i++)
			li.add(new Student("王" + i, i % 3 == 0 ? Sex.男 : Sex.女, 20 + i));
		XMLEncoder xd = new XMLEncoder(new FileOutputStream("stus.xml"));
		xd.writeObject(li);//
		xd.close();

		XMLDecoder xe = new XMLDecoder(new FileInputStream("stus.xml"));
		List<Student> l3 = (List<Student>) xe.readObject();
		xe.close();
		System.out.println(l3);
	}

}
